package com.ysstech.activiti.listener;


import com.ysstech.activiti.feign.FeignRoleService;
import com.ysstech.common.util.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
public class YssExecutionListenerSuccess implements ExecutionListener {

   private FeignRoleService feignRoleService = null;
    @Override
    public void notify(DelegateExecution delegateExecution) {
        try {
            //execution是流程实例的代理对象
            String businessKey = delegateExecution.getProcessInstanceBusinessKey();
            if (StringUtils.isBlank(businessKey)) {
                log.error("监听程序没有获取到流程发起的objId！");
                return;
            }
            String key = businessKey.split("\\.")[0];
            String id = businessKey.split("\\.")[1];
            feignRoleService = SpringContextUtil.getBean(FeignRoleService.class);
            switch (key) {
                case "role":
                    feignRoleService.updateRoleStatus(id, "0"); // 审核通过状态
                    break;
                default:
                    log.error("没有获取到对应的流程的key！");
                    break;
            }
        } catch (Exception ex) {
            log.error(ex.toString());
        }
    }
}
